from colorama import init,Fore,Style,Back
from classifier import Classifier
from parse import Parse
from answer import Answer
import os

class ChatRobot:
    def __init__(self):
        init(autoreset=True)
        print("====================================")
        print(Back.BLUE+"欢迎进入智慧医疗问答面板！")
        print("====================================")

    def main(self, question):
        print("")
        # print(Fore.RED + "小北正在思考中……")
        # print("")

        default_answer = "您好，小北知识有限，暂时回答不上来，正在努力迭代中！"
        final_classify = Classifier().classify(question)
        # print(final_classify)
        parse_sql = Parse().main(final_classify)
        # print(parse_sql)
        final_answer = Answer().main(parse_sql)

        if not final_answer:
            return default_answer

        return "\n\n".join(final_answer)

if __name__ == "__main__":
    robot = ChatRobot()
    while 1:
        print(" ")
        question = input("您问：")

        if "关闭" in question:
            print("")
            print("小北说：", "好的，已经关闭了哦，欢迎您下次提问~")
            break;

        answer = robot.main(question)

        print(Fore.LIGHTRED_EX+"小北答：", Fore.GREEN + answer)